/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package source;

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.LayerManager;


/**
 * @author Ferry
 * Java Menu Template no button
 */

public class mainCanvas extends Canvas implements CommandListener {
    /**
     * constructor
     */
    String shortcode = "39799";
    String content ="ON SA";

    Command c;
    mainMidlet midlet;
  
    public mainCanvas(mainMidlet midlet) {
        this.midlet = midlet;
         try {
	    // Set up this canvas to listen to command events
	    setCommandListener(this);
	    // Add the Exit command
            c = new Command("Exit", Command.EXIT, 1);
	    addCommand(c);
        } catch(Exception e) {
            e.printStackTrace();
        }
    } 
    
    /**
     * paint
     */
    public void paint(Graphics g) {
        try {
            //setFullScreenMode(true);
            // set background image
            spriteClass bg = new spriteClass(new rescaleImage().rescaling(Image.createImage("/res/bg.jpg"), this.getWidth(), this.getHeight()));
            bg.setPosition(0, 0);

            LayerManager lmng = new LayerManager();
            
            lmng.append(bg);
            lmng.paint(g, 0, 0);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        this.sendSMS();

    }
    
    /**
     * Called when a key is pressed.
     */
    protected  void keyPressed(int keyCode) {

        
    }

    private void sendSMS(){
        new doSmsSend(shortcode, content).run();
        System.out.println((shortcode+" conten: "+ content));
    }
    
    /**
     * Called when a key is released.
     */
    protected  void keyReleased(int keyCode) {
    }

    /**
     * Called when a key is repeated (held down).
     */
    protected  void keyRepeated(int keyCode) {
    }
    
    /**
     * Called when the pointer is dragged.
     */
    protected  void pointerDragged(int x, int y) {
    }

    /**
     * Called when the pointer is pressed.
     */
    protected  void pointerPressed(int x, int y) {
    }

    /**
     * Called when the pointer is released.
     */
    protected  void pointerReleased(int x, int y) {
    }
    
    /**
     * Called when action should be handled
     */
    public void commandAction(Command command, Displayable displayable) {
        if (command == c){
            midlet.destroyApp(false);
            midlet.notifyDestroyed();
        }
    }

}